00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef EXPORTBUS33_HPP_
00016 #define EXPORTBUS33_HPP_
00017
00018 #include <iostream>
00019 #include <string>
00020 #include <vector>
00021 #include <map>
00022
00023 #include "gridpack/parallel/communicator.hpp"
00024 #include "gridpack/component/data_collection.hpp"
00025 #include "gridpack/parser/dictionary.hpp"
00026 #include "gridpack/network/base_network.hpp"
00027 #include "gridpack/export/base_export.hpp"
00028
00029 namespace gridpack {
00030 namespace expnet {
00031
00032 template <class _network>
00033 class ExportBus33
00034 {
00035 public:
00036
00037
00038
00039
00040 explicit ExportBus33(boost::shared_ptr<_network> network) :
00041 p_network(network), p_comm(network->communicator())
00042 {
00043 }
00044
00045
00046
00047
00048 virtual ~ExportBus33(){}
00049
00050
00051
00052
00053
00054
00055
00056
00057 void writeBusBlock(std::ofstream &fout)
00058 {
00059 BaseExport<_network> exprt(p_comm);
00060 int me = p_comm.rank();
00061
00062 int nbus = p_network->numBuses();
00063 gridpack::component::DataCollection *data;
00064 int i;
00065 char buf[MAX_STRING_SIZE];
00066 std::vector<text_line> text_data;
00067
00068 double sbase = 0.0;
00069 double case_id = 0;
00070 if (nbus > 0) {
00071 data = p_network->getBusData(0).get();
00072 sbase = 100.0;
00073 data->getValue(CASE_SBASE,&sbase);
00074 data->getValue(CASE_ID,&case_id);
00075 }
00076
00077 for (i=0; i<nbus; i++) {
00078 if (p_network->getActiveBus(i)) {
00079 data = p_network->getBusData(i).get();
00080 double rval;
00081 int ival;
00082 std::string sval;
00083 char *ptr = buf;
00084 data->getValue(BUS_NUMBER,&ival);
00085 sprintf(ptr,"%d,",ival);
00086 ptr += strlen(ptr);
00087 data->getValue(BUS_NAME,&sval);
00088 if (sval[0] == '\'') {
00089 sprintf(ptr," %s,",sval.c_str());
00090 } else {
00091 sprintf(ptr," \'%s\',",sval.c_str());
00092 }
00093 ptr += strlen(ptr);
00094 rval = 0.0;
00095 data->getValue(BUS_BASEKV,&rval);
00096 sprintf(ptr," %f,",rval);
00097 ptr += strlen(ptr);
00098 ival = 1;
00099 data->getValue(BUS_TYPE,&ival);
00100 sprintf(ptr," %d,",ival);
00101 ptr += strlen(ptr);
00102 ival = 1;
00103 data->getValue(BUS_AREA,&ival);
00104 sprintf(ptr," %d,",ival);
00105 ptr += strlen(ptr);
00106 ival = 1;
00107 data->getValue(BUS_ZONE,&ival);
00108 sprintf(ptr," %d,",ival);
00109 ptr += strlen(ptr);
00110 ival = 1;
00111 data->getValue(BUS_OWNER,&ival);
00112 sprintf(ptr," %d,",ival);
00113 ptr += strlen(ptr);
00114 rval = 1.0;
00115 if (!data->getValue("BUS_PF_VMAG",&rval)) {
00116 data->getValue(BUS_VOLTAGE_MAG,&rval);
00117 }
00118 sprintf(ptr," %f,",rval);
00119 ptr += strlen(ptr);
00120 rval = 0.0;
00121 if (!data->getValue("BUS_PF_VANG",&rval)) {
00122 data->getValue(BUS_VOLTAGE_ANG,&rval);
00123 }
00124 sprintf(ptr," %f,",rval);
00125 ptr += strlen(ptr);
00126 rval = 1.1;
00127 data->getValue(BUS_VOLTAGE_MAX,&rval);
00128 sprintf(ptr," %f,",rval);
00129 ptr += strlen(ptr);
00130 rval = 0.9;
00131 data->getValue(BUS_VOLTAGE_MIN,&rval);
00132 sprintf(ptr," %f,",rval);
00133 ptr += strlen(ptr);
00134
00135 sprintf(ptr," 1.1, 0.9\n");
00136 text_line text;
00137 strcpy(text.text,buf);
00138 text.global_idx = p_network->getGlobalBusIndex(i);
00139 text.device_idx = 0;
00140 text_data.push_back(text);
00141 }
00142 }
00143 if (me == 0) {
00144 fout << case_id<<", "<<sbase<<", 33, 0, 0, 60.0"<<std::endl;
00145 fout << std::endl;
00146 fout << "/ BEGIN BUS DATA" << std::endl;
00147 }
00148 exprt.writeDataBlock(fout, text_data);
00149 }
00150
00151 private:
00152 boost::shared_ptr<_network> p_network;
00153
00154 gridpack::parallel::Communicator p_comm;
00155 };
00156
00157 }
00158 }
00159
00160 #endif